/**
 * @(#)Bootstrap.java 0.0.1-SNAPSHOT
 *
 * Copyright Group B
 */
package grupb.upf.main;

import grupb.upf.Controller.Controller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
 * <p>This class starts the p2piki GUI.</p>
 * <p>Sample: To run (it invokes <code>start</code> method)</p>
 * <PRE>
 * java -jar grupb.upf start
 * or
 * java grupb.upf.main.Bootstrap start
 * </PRE>
 * @version    0.0.1-SNAPSHOT
 * @author     Group B
 */
public class Bootstrap {
    /**
     * The logger. A new logger <code>grupb.upf.Bootstrap</code> is created to
     * add the logs of this Bootstrap.
     */
    private static final Log LOG = LogFactory.getLog(Bootstrap.class);

    /**
     * The start method.
     */
    private static final String START_METHOD = "start";
    /**
     * The stop method.
     */
    private static final String STOP_METHOD = "stop";
    /**
     * The method to be executed. By default is <code>START_METHOD</code>.
     */
    private static String method = START_METHOD;

    /**
     * <p>This method parses the command line.</p>
     * @param args the received parameters
     */
     private static void parseArgs(final String [] args) {
         if (args.length == 1) {
             if (args[0].equals(START_METHOD)) {
                 method = START_METHOD;
             } else if (args[0].equals(STOP_METHOD)) {
                 method = STOP_METHOD;
             } else {
                StringBuffer err = new StringBuffer()
                        .append("Error in Main, the argument isn't correct: ")
                        .append(args[0])
                        .append("\nIt can be: < start >or < stop >");
                LOG.error(err);
                System.exit(1);
            }
         } else if (args.length > 1) {
           LOG.error("Error in Main, there is only necessary 1 argument");
           System.exit(1);
        } else {
           LOG.error("Error in Main, there is necessary 1 argument");
           System.exit(1);
        }
     }
    /**
     * <p>The method <code>start</code> initialize the execution of the sample
     * GUI, which let us to use the clases created.</p>
     */
    public static void start() {
        final Controller controller =
                new grupb.upf.Controller.impl.Controller();
    }

    /**
     * <p>The method <code>stop</code> stops the execution of the sample of
     * use.</p>
     * <p>If the component isn't a server this method isn't use.</p>
     */
    private static void stop() {
        throw new UnsupportedOperationException("Not implemented");
    }

    /**
     * <p>
     * The method <code>main</code> launch the application.</p>
     * @param args an Array of Strings
     */
     public static void main(final String [] args) {
        parseArgs(args);
        if (method.equals(START_METHOD)) {
            start();
        } else if (method.equals(STOP_METHOD)) {
            stop();
        }
    }
}
